package cn.icanci.loopstack.amc.sample.service.impl;

import cn.icanci.loopstack.amc.cloud.common.request.MockCallRequest;
import cn.icanci.loopstack.amc.cloud.common.response.MockCallResponse;
import cn.icanci.loopstack.amc.cloud.common.utils.MockCallUtils;
import cn.icanci.loopstack.amc.sample.service.MockCallService;
import cn.icanci.loopstack.api.client.Client;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author icanci
 * @since 1.0 Created in 2023/01/17 10:31
 */
@Service
public class MockCallServiceImpl implements MockCallService {
    private static final Logger logger = LoggerFactory.getLogger(MockCallServiceImpl.class);

    @Resource
    private Client              httpClient;

    @Value("${amc.url}")
    private String              amcUrl;

    @Override
    public void testMockCall(String mockUuid) {
        MockCallRequest request = new MockCallRequest();
        request.setTraceId("xxxxxxxx");
        request.setMockCallUuid("AMC1630403667985313792");
        request.setMockRequest("{}");

        MockCallResponse call = MockCallUtils.doMockCall(request, "http://127.0.0.1:9996/mock/call/invoke");
        String s = String.valueOf(call.getWrapper().getMockResponse());
        System.out.println(s);
        //        MockCallRequest request = new MockCallRequest();
        //        request.setTraceId(UUID.randomUUID().toString());
        //        request.setMockCallUuid(mockUuid);
        //        HashMap<Object, Object> obj = new HashMap<>();
        //        obj.put("uuid", UUID.randomUUID().toString());
        //        request.setMockRequest(JSONUtil.toJsonStr(obj));
        //        Client.RpcRequest rpcRequest = new Client.RpcRequest(amcUrl, request, Maps.newHashMap(), Method.POST, 3, TimeUnit.SECONDS, 0);
        //        logger.info("[MockCallService][testMockCall] req:{}", JSONUtil.toJsonStr(request));
        //        MockCallResponse call = httpClient.call(rpcRequest, MockCallResponse.class);
        //        //        MockCallWrapper wrapper = call.getWrapper();
        //        //        Object mockResponse = wrapper.getMockResponse();
        //        //
        //        //        System.out.println(WrapperUtils.toStringValue(mockResponse));
        //        //        Quota x = WrapperUtils.toObjectBean(mockResponse, Quota.class);
        //        //        System.out.println(x);
        //
        //        logger.info("[MockCallService][testMockCall] resp:{}", JSONUtil.toJsonStr(call.getWrapper()));
        //        System.out.println();
    }
}
